﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Manager.ClothManager
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                //绑定布料公司
                string cmdstr = "select * from ClothCompany where active=1 order by sequence asc";
                SqlHelper.BindDropDownList(ddlCompany,"shortName","ID",SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null);
                ddlCompany.Items.Insert(0,"--select--");

                bindCloth();
            }
        }

        //绑定
        protected void bindCloth()
        {
            ViewState["limit"] = " where 1=1";
            if (clothNo.Text.Trim() != "")
            {
                ViewState["limit"] += " and clothNo like '%"+clothNo.Text.Trim()+"%'";
            }
            if (ddlCompany.SelectedIndex != 0)
            {
                ViewState["limit"] += " and companyID="+ddlCompany.SelectedValue;
            }
            string cmdstr = "select count(*) from ClothView " + ViewState["limit"].ToString();
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","ClothView"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }

        //搜索
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            bindCloth();
        }

        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindCloth();
        }
    }
}